slicelistmodel: Make constructor transfer full
authorMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 19:38:15 +0000 (15:38 -0400)
committerMatthias Clasen <mclasen@redhat.com>
Sun, 26 Jul 2020 22:04:40 +0000 (18:04 -0400)
This is for consistency with other wrapping list constructors.
We want them all to be transfer full, allow-none.

Update all callers.

gtk/gtkslicelistmodel.c
testsuite/gtk/slicelistmodel.c

index 8d0273c0371ed4b3fe605156d830a95e7d861d26..523a3b1c6d83ea36caedd014a941835ce4a41234 100644 (file)
  * @short_description: A list model that presents a slice out of a larger list
  * @see_also: #GListModel
  *
- * #GtkSliceListModel is a list model that takes a list model and presents a slice of
- * that model.
+ * #GtkSliceListModel is a list model that takes a list model and presents a
+ * slice of that model.
  *
- * This is useful when implementing paging by setting the size to the number of elements
- * per page and updating the offset whenever a different page is opened.
+ * This is useful when implementing paging by setting the size to the number
+ * of elements per page and updating the offset whenever a different page is
+ * opened.
  */
 
 #define DEFAULT_SIZE 10
@@ -300,7 +301,7 @@ gtk_slice_list_model_init (GtkSliceListModel *self)
 
 /**
  * gtk_slice_list_model_new:
- * @model: (transfer none) (allow-none): The model to use
+ * @model: (transfer full) (allow-none): The model to use, or %NULL
  * @offset: the offset of the slice
  * @size: maximum size of the slice
  *
@@ -314,13 +315,20 @@ gtk_slice_list_model_new (GListModel *model,
                           guint       offset,
                           guint       size)
 {
+  GtkSliceListModel *self;
+
   g_return_val_if_fail (model == NULL || G_IS_LIST_MODEL (model), NULL);
 
-  return g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
+  self = g_object_new (GTK_TYPE_SLICE_LIST_MODEL,
                        "model", model,
                        "offset", offset,
                        "size", size,
                        NULL);
+
+  /* consume the reference */
+  g_clear_object (&model);
+
+  return self;
 }
 
 /**
index 631444182fd8c06fcbb874dd498991c74d046a0f..b57eb253fe5828255f936861be65628f3d0814b4 100644 (file)
@@ -191,6 +191,8 @@ new_model (GListStore *store, guint offset, guint size)
   GtkSliceListModel *result;
   GString *changes;
 
+  if (store)
+    g_object_ref (store);
   result = gtk_slice_list_model_new (G_LIST_MODEL (store), offset, size);
 
   changes = g_string_new ("");